-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow complex values in variables parameter of terraform module #4281
Allow complex values in variables parameter of terraform module #4281
Conversation
Signed-off-by: Webster Mudge <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! Can you please add a changelog fragment? Thanks.
@@ -443,7 +443,7 @@ def main(): | |||
for k, v in variables.items(): | |||
variables_args.extend([ | |||
'-var', | |||
'{0}={1}'.format(k, v) | |||
'{0}={1}'.format(k, json.dumps(v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does terraform interpret arguments of -var
? I'm wondering whether this is a breaking change or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please comment on this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so, as I haven't hit any issues with this patch in my use cases. That said, I just reread the TF docs on the topic (see Input Variables on the Command Line and Assigning Values to Root Module Variables), and the references all seem to point to TF "native" expressions. However, JSON Configuration Syntax states that "Everything that can be expressed in native syntax can also be expressed in JSON syntax, but some constructs are more complex to represent in JSON due to limitations of the JSON grammar."
I'll run some more tests to see if I can break this, but I would think that if you have really complex variables, you are best served by creating your own variables file and passing that as a reference. The intention of this patch is to allow "simple" complex variables, like list(string)
, to be declared in the variables
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your explanations and links! Sounds convincing to me. (I'm not using terraform so I can't test myself.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has turned out to be a breaking change. See #4367.
Signed-off-by: Webster Mudge <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
The change looks reasonable to me. If nobody complains, I'll merge in ~a week. |
Backport to stable-3: 💚 backport PR created✅ Backport PR branch: Backported as #4340 🤖 @patchback |
@wmudge thanks a lot for your contribution! |
* Allow complex values in variables parameter Signed-off-by: Webster Mudge <[email protected]> * Add changelog fragment Signed-off-by: Webster Mudge <[email protected]> * Update changelogs fragments formatting Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 4cc7f41)
Backport to stable-4: 💚 backport PR created✅ Backport PR branch: Backported as #4341 🤖 @patchback |
* Allow complex values in variables parameter Signed-off-by: Webster Mudge <[email protected]> * Add changelog fragment Signed-off-by: Webster Mudge <[email protected]> * Update changelogs fragments formatting Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 4cc7f41)
… (#4340) * Allow complex values in variables parameter Signed-off-by: Webster Mudge <[email protected]> * Add changelog fragment Signed-off-by: Webster Mudge <[email protected]> * Update changelogs fragments formatting Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 4cc7f41) Co-authored-by: Webster Mudge <[email protected]>
… (#4341) * Allow complex values in variables parameter Signed-off-by: Webster Mudge <[email protected]> * Add changelog fragment Signed-off-by: Webster Mudge <[email protected]> * Update changelogs fragments formatting Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 4cc7f41) Co-authored-by: Webster Mudge <[email protected]>
This has completely broken my existing playbooks. See #4367. 2 hours of "what could possibly have changed, what do you mean |
You could have simply told people to pass complex values through the This "fix" forces everything through |
Specifically, this breaks PLAIN STRINGS.
Complex data that has already gone through a |
@earchibald-lv is correct - this change is not just not backwards compatible, but is also actually totally broken in the way that it now handles string values. I have some code that uses the
However at 4.6.0 this produces a validation error. I can fix this for 4.6.0 by switching to:
which is fine - in fact I probably prefer it. But I then get bitten by the following error:
Now this network definitely exists, and the code was working up until yesterday so I was mystified as to what was going on, because the error message seems sensible. It took me ages to figure out that the reason it was failing is because the quotes are being treated as part of the network name. For now, I will be sticking at 4.5.0, unfortunately. |
I believe the backwards-compatible fix may be just "don't encode strings as JSON, other types are fine" but there should probably be a more comprehensive look at this before a new release. I'd very much like a 4.6.1 with this change removed, and to see this circled back to in a later release, with time to be better-tested. I agree with @mkjpryor that being able to get rid of all the filter pipes |
@earchibald-lv I think it is easier than that - the fix can be "only encode |
There may also be others like |
I actually don't mind the |
The "oh, jeez, what about that case" is the classic path to an unexpected break like this :) I agree re: the filters and control, which skipping strings would allow*. The most important part is that it is compatible and predicable and tested.
|
@earchibald-lv Totally agree. IMHO, this PR should be reverted and a 4.6.1 release cut. In order to re-propose the change, we need a test suite that covers as many different types of variable as possible to ensure this doesn’t happen again. But I’m actually happy with how it is at 4.5.0 TBH. |
…le (ansible-collections#4281)" This reverts commit 4cc7f41.
I agree this should better be reverted for now. PR to revert this change from |
Some useful tests would be a good idea indeed. Right now there is one single unit test in tests/unit/plugins/modules/cloud/misc/test_terraform.py which checks that the module fails if called without any arguments. This isn't much more helpful than having no tests at all. It would also be helpful if more folks could look at proposed changes and comment on them. |
…le (ansible-collections#4281)" (ansible-collections#4368) This reverts commit 4cc7f41. (cherry picked from commit 9618fb9)
Signed-off-by: Webster Mudge [email protected]
SUMMARY
Allow complex, i.e. lists and dictionaries, values in the
variables
parameter of theterraform
module. Without this minor patch, complex values will fail due to formatting issues, i.e.Single quotes are not valid. Use double quotes (\") to enclose strings.
ISSUE TYPE
COMPONENT NAME
community.general.terraform